package com.neuedu.service.impl;

import com.neuedu.dao.AdminDao;
import com.neuedu.entity.Admin;
import com.neuedu.service.AdminService;

import java.util.List;

/**
 * @标 题： 龙猫电商管理平台
 * @项目名称： YD-WebShop
 * @描 述：
 * @作 者： 侯建军
 * @日 期： 2019/6/19  10:25
 */
public class AdminServiceImpl implements AdminService {
    AdminDao adminDao = new AdminDao();

    @Override
    public boolean register(Admin admin) {
        List<Admin> list = adminDao.findByWhere(" AND adminName='" + admin.getAdminName() + "'");
        if (list.size() == 0) {
            return adminDao.insert(admin);
        }
        return false;
    }

    @Override
    public Admin login(String adminName, String password) {
        String where = "AND adminName='" + adminName + "' AND password='" + password + "'";
        List<Admin> list = adminDao.findByWhere(where);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    public static void main(String[] args) {
        AdminServiceImpl adminService = new AdminServiceImpl();
//        Admin admin=new Admin();
//        admin.setAdminName("李四");
//        admin.setPassword("000000");
//        admin.setCreatetime(new Date());
//        if(adminService.register(admin)){
//            System.out.print("注册成功");
//        }else{
//            System.out.print("注册失败");
//        }
        Admin admin = adminService.login("zhangsan", "000000");
        if (null != admin) {
            System.out.print("登录成功");
        } else {
            System.out.print("登录失败");
        }
    }
}
